/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VistaConexion;

import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author warlock
 */
public class JDialogTableDatos extends javax.swing.JDialog {

    /**
     * Creates new form JDialogTableDatos
     */
    ArrayList<ArrayList<String>> tabla;
    ArrayList<String> columnas;
    DefaultTableModel modelo;
    public JDialogTableDatos(java.awt.Frame parent, boolean modal, ArrayList<ArrayList<String>> tabla, ArrayList<String> columnas) {
        super(parent, modal);
        initComponents();
        this.tabla = tabla;
        this.columnas = columnas;
        this.modelo = (DefaultTableModel) jTable1.getModel();
        modelo.setColumnCount(this.columnas.size());
        modelo.setColumnIdentifiers(this.columnas.toArray());
        System.err.println(this.columnas.toArray().length);
        actualizar_tabla();
        

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new TablaModelo());
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void actualizar_tabla(){
        modelo = (DefaultTableModel) jTable1.getModel();
        for(int i=0; i<this.tabla.size(); i++){
            ArrayList<String> row = this.tabla.get(i);
            modelo.addRow(row.toArray());
            System.out.println(row.toArray());
        }
        TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modelo);
        jTable1.setRowSorter(sorter);
    }
    /**
     * @param args the command line arguments
     */
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
